var myApp = angular.module('starter.controllers', [])

    .controller('AppCtrl', function ($scope, $ionicModal, $timeout, $ionicSideMenuDelegate) {
        // Form data for the login modal
        $scope.loginData = {};

        // Create the login modal that we will use later
        $ionicModal.fromTemplateUrl('templates/login.html', {
            scope: $scope
        }).then(function (modal) {
                $scope.modal = modal;
            });

        // Triggered in the login modal to close it
        $scope.closeLogin = function () {
            $scope.modal.hide();
        };

        // Open the login modal
        $scope.login = function () {
            $scope.modal.show();
        };

        // Perform the login action when the user submits the login form
        $scope.doLogin = function () {
            console.log('Doing login', $scope.loginData);

            // Simulate a login delay. Remove this and replace with your login
            // code if using a login system
            $timeout(function () {
                $scope.closeLogin();
            }, 1000);
        };
    })
    .controller('PlaylistsCtrl', function ($scope, $ionicSideMenuDelegate) {
        $scope.playlists = [
            { title: 'Reggae', id: 1 },
            { title: 'Chill', id: 2 },
            { title: 'Dubstep', id: 3 },
            { title: 'Indie', id: 4 },
            { title: 'Rap', id: 5 },
            { title: 'Cowbell', id: 6 }
        ];
        $scope.toggleRightSideMenu = function () {
            $ionicSideMenuDelegate.toggleRight();
        };
    })
    .controller('PlaylistCtrl', function ($scope, $stateParams) {

    })
    .controller('Category', function ($scope, $ionicModal) {

        $scope.data = {
            showDelete: false
        };

        $scope.edit = function (item) {
            alert('Edit Item: ' + item.id);
        };
        $scope.share = function (item) {
            alert('Share Item: ' + item.id);
        };

        $scope.moveItem = function (item, fromIndex, toIndex) {
            $scope.items.splice(fromIndex, 1);
            $scope.items.splice(toIndex, 0, item);
        };

        $scope.onItemDelete = function (item) {
            $scope.items.splice($scope.items.indexOf(item), 1);
        };

        $scope.items = [
            { id: 0, name_category: "Nước giải khát"},
            { id: 1, name_category: "Thuốc lá"},
            { id: 2, name_category: "Đồ ăn vặt"},
            { id: 3, name_category: "Bia rượu"},
            { id: 4, name_category: "Gia vị bếp"}
        ];

        $ionicModal.fromTemplateUrl('templates/add_category.html', {
            animation: 'slide-in-up',
            scope: $scope
        }).then(function (modal) {
                $scope.modal = modal;
            });


        $scope.AddCategory = function () {
            $scope.data = {}
            $scope.modal.show();
        }

    })

    .controller('Customer', function ($scope, $ionicModal) {

        $scope.data = {
            showDelete: false
        };
        $scope.moveItem = function (item, fromIndex, toIndex) {
            $scope.items.splice(fromIndex, 1);
            $scope.items.splice(toIndex, 0, item);
        };

        $scope.onItemDelete = function (item) {
            $scope.items.splice($scope.items.indexOf(item), 1);
        };

        $ionicModal.fromTemplateUrl('templates/add_customer.html', {
            animation: 'slide-in-up',
            scope: $scope
        }).then(function (modal) {
                $scope.modal = modal;
            });


        $scope.AddCustomer = function () {
            $scope.data = {}
            $scope.modal.show();
        }
        $scope.items = [
            { id: 0, name_customer: "Minh Ngoc"},
            { id: 1, name_customer: "Hoang Thanh"},
            { id: 2, name_customer: "Xuan Quynh"},
            { id: 3, name_customer: "Hong Ngoc"},
            { id: 4, name_customer: "Thanh Tam"}
        ];

    })
    .controller('Tax', function ($scope, $ionicModal) {

        $scope.data = {
            showDelete: false
        };
        $scope.moveItem = function (item, fromIndex, toIndex) {
            $scope.items.splice(fromIndex, 1);
            $scope.items.splice(toIndex, 0, item);
        };

        $scope.onItemDelete = function (item) {
            $scope.items.splice($scope.items.indexOf(item), 1);
        };

        $ionicModal.fromTemplateUrl('templates/add_tax.html', {
            animation: 'slide-in-up',
            scope: $scope
        }).then(function (modal) {
                $scope.modal = modal;
            });

        $scope.AddTax = function () {
            $scope.data = {}

            $scope.modal.show();
        }
        $scope.items = [
            { id: 0, name_tax: "Thuế 5%"},
            { id: 1, name_tax: "Thuế 10%"},
            { id: 2, name_tax: "Thuế 15%"},
            { id: 3, name_tax: "Thuế 20%"},
            { id: 4, name_tax: "Thuế 50%"}
        ];

    })
    .controller('Discount', function ($scope, $ionicModal) {

        $scope.data = {
            showDelete: false
        };
        $scope.moveItem = function (item, fromIndex, toIndex) {
            $scope.items.splice(fromIndex, 1);
            $scope.items.splice(toIndex, 0, item);
        };

        $scope.onItemDelete = function (item) {
            $scope.items.splice($scope.items.indexOf(item), 1);
        };

        $ionicModal.fromTemplateUrl('templates/add_discount.html', {
            animation: 'slide-in-up',
            scope: $scope
        }).then(function (modal) {
                $scope.modal = modal;
            });
        $scope.AddDiscount = function () {
            $scope.data = {}
            $scope.modal.show();

        }
        $scope.items = [
            { id: 0, name_discount: "Giảm 5%"},
            { id: 1, name_discount: "Giảm 10%"},
            { id: 2, name_discount: "Giảm 15%"},
            { id: 3, name_discount: "Giảm 20%"},
            { id: 4, name_discount: "Giảm 50%"}
        ];

    });
